<template>
	<view class="container">
		<!-- 养殖管理 -->
		<view class="management-block">
			<view class="block-title">养殖管理</view>
			<view class="function-grid">
				<view class="function-item" v-for="item in breedingManagement" :key="item.name" @click="scanHandle">
					<image :src="item.icon" class="item-icon"></image>
					<text class="item-text">{{ item.name }}</text>
				</view>
			</view>
		</view>

		<!-- 物资管理 -->
		<view class="management-block">
			<view class="block-title">物资管理</view>
			<view class="function-grid">
				<view class="function-item" v-for="item in materialManagement" :key="item.name" @click="scanHandle">
					<image :src="item.icon" class="item-icon"></image>

					<text class="item-text">{{ item.name }}</text>
				</view>
			</view>
		</view>

		<!-- 场地管理 -->
		<view class="management-block">
			<view class="block-title">场地管理</view>
			<view class="function-grid">
				<view class="function-item" v-for="item in siteManagement" :key="item.name" @click="scanHandle">
					<image :src="item.icon" class="item-icon"></image>
					<text class="item-text">{{ item.name }}</text>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				breedingManagement: [{
						name: '报备',
						icon: '/static/1.png'
					},
					{
						name: '水质',
						icon: '/static/2.png'
					},
					{
						name: '投料',
						icon: '/static/3.png'
					},
					{
						name: '动保',
						icon: '/static/4.png'
					},
					{
						name: '日志',
						icon: '/static/5.png'
					}
				],
				materialManagement: [{
						name: '供应商',
						icon: '/static/6.png'
					},
					{
						name: '饲料',
						icon: '/static/7.png'
					},
					{
						name: '动保',
						icon: '/static/4.png'
					},
					{
						name: '设备',
						icon: '/static/8.png'
					}
				],
				siteManagement: [{
						name: '基地',
						icon: '/static/9.png'
					},
					{
						name: '片区',
						icon: '/static/10.png'
					}
				]
			};
		},
		methods: {
			scanHandle() {
				uni.showToast({
					title:'请先绑定设备',
					icon:'none'
				})
				// 扫描设备逻辑
				uni.scanCode({
					success: function(res) {
						console.log('条码类型：' + res.scanType);
						console.log('条码内容：' + res.result);
					}
				});
			}
		}
	};
</script>

<style lang="scss" scoped>
	.container {
		background-color: #f5f5f5; // 整体灰色背景
		padding: 20rpx;
		min-height: 100vh;
	}

	.management-block {
		background-color: #fff; // 三块白色背景
		border-radius: 16rpx;
		margin-bottom: 20rpx;
		padding: 20rpx;
	}

	.block-title {
		font-size: 32rpx;
		margin-bottom: 20rpx;
	}

	.function-grid {
		display: flex;
		flex-wrap: wrap;
	}

	.function-item {
		width: 25%; // 一行四个
		display: flex;
		flex-direction: column;
		align-items: center;
		margin-bottom: 30rpx;
	}

	.item-icon {
		width: 80rpx;
		height: 80rpx;
		margin-bottom: 10rpx;
	}

	.item-text {
		font-size: 24rpx;
		text-align: center;
	}
</style>